/**
 * Yolema.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */
package org.grayrabbit.pay.core.biz.manager.transaction.impl;

import org.grayrabbit.pay.core.biz.manager.transaction.TradeRecordManager;
import org.grayrabbit.pay.core.model.entity.transaction.TradeRecord;
import org.grayrabbit.pay.core.model.enums.TradeEnum;
import org.grayrabbit.pay.core.model.pages.PageList;
import org.grayrabbit.pay.core.model.results.GenericsResult;
import org.grayrabbit.pay.core.model.results.PayResult;
import org.grayrabbit.pay.core.service.transaction.TradeRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 
 * 
 * @author liyd
 * @version $Id: TradeRecordManagerImpl.java, v 0.1 Thu May 31 14:50:37 CST 2012 liyd Exp $
 */
@Component
public class TradeRecordManagerImpl implements TradeRecordManager {

    @Autowired
    private TradeRecordService tradeRecordService;

    /**
     * 查询业务列表
     * 
     * @param district
     * @return
     */

    public GenericsResult<PageList<TradeRecord>> queryPageList(TradeRecord tradeRecord) {

        GenericsResult<PageList<TradeRecord>> result = new GenericsResult<PageList<TradeRecord>>(
            true);
        PageList<TradeRecord> list = tradeRecordService.queryPageList(tradeRecord);
        for (TradeRecord atrade : list) {
            atrade.setStatusEnum(TradeEnum.getTradeEnum(atrade.getOrderStatus()));
        }
        result.setResultData(list);

        return result;
    }

    /**
     * 根据Id得到实体对象
     * 
     * @param id
     * @return
     */
    public GenericsResult<TradeRecord> getById(Long id) {

        GenericsResult<TradeRecord> result = new GenericsResult<TradeRecord>(true);

        result.setResultData(tradeRecordService.getById(id));

        return result;

    }

    /**
     * 根据id批量删除
     * 
     * @param idArray
     * @return
     */
    public PayResult deleteBatchById(Long[] idArray) {

        PayResult result = new PayResult(true);

        tradeRecordService.deleteBatchById(idArray);

        return result;
    }

    /**
     * 添加一个对象
     * 
     * @param tradeRecord
     * @return
     */
    public GenericsResult<TradeRecord> insert(TradeRecord tradeRecord) {

        GenericsResult<TradeRecord> result = new GenericsResult<TradeRecord>(true);

        tradeRecordService.insert(tradeRecord);

        return result;

    }

    /**
     * 更新一个对象
     * 
     * @param tradeRecord
     * @return
     */
    public GenericsResult<Integer> update(TradeRecord tradeRecord) {

        GenericsResult<Integer> result = new GenericsResult<Integer>(true);

        result.setResultData(tradeRecordService.update(tradeRecord));

        return result;
    }

    /**
     * 删除一个对象
     * 
     * @param tradeRecord
     * @return 
     */
    public PayResult delete(TradeRecord tradeRecord) {

        PayResult result = new PayResult(true);

        tradeRecordService.delete(tradeRecord);

        return result;
    }

}
